#include <bits/stdc++.h>

using namespace std;

int main() {
    int N, X;
    cin >> N;
    vector<int> price(N);
    for (int i = 0; i < N; ++i) cin >> price[i];
    cin >> X;
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (X >= price[i]) {
            X -= price[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}